import { defHttp } from '/@/utils/http/axios';
import { getAttrListResultModel, GetAttrListParams, Attr } from './model/attrModel';

enum Api {
  GetAttrList = '/admin/product/attrInfoList',
  RemoveAttr = '/admin/product/deleteAttr',
  SaveOrUpdateAttr = '/admin/product/saveAttrInfo',
}

/**
 * @description: 获取attr列表
 */
export function getAttrListApi({ category1Id, category2Id, category3Id }: GetAttrListParams) {
  return defHttp.get<getAttrListResultModel>({
    url: Api.GetAttrList,
    params: `/${category1Id}/${category2Id}/${category3Id}`,
  });
}

/**
 * @description: 新增或修改attr
 */
export function saveOrUpdateAttrApi(data: Attr) {
  return defHttp.post<null>({
    url: Api.SaveOrUpdateAttr,
    data,
  });
}

/**
 * @description: 删除attr
 */
export function removeAttrApi(attrId: number) {
  return defHttp.delete<null>({
    url: Api.RemoveAttr,
    params: `/${attrId}`,
  });
}
